package cn.klaw.base.model.language;

import cn.klaw.model.ExcelColumnAttr;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.util.*;

/**
 * 多语言导入模型
 *
 *
 * @version v5.0.0
 *
 * @date 2024/6/25 15:31:23
 */
public class BaseLangColumn {

    String excelName = "翻译管理";

    Map<String, String> keyMap = new LinkedHashMap() {{
        put("enCode", "翻译标记");
        put("type", "翻译分类");
    }};

    public BaseLangColumn(Map<String, String> keyMap) {
        this.keyMap.putAll(keyMap);
    }

    /**
     * 表格名称
     *
     * @return
     */
    public String getExcelName() {
        return excelName;
    }

    /**
     * 根据类型获取excel表头字段
     *
     * @param type
     * @return
     */
    public Map<String, String> getColumnByType(Integer type) {
        return keyMap;
    }

    /**
     * 获取字段列表
     *
     * @param isError
     * @return
     */
    public List<ExcelColumnAttr> getFieldsModel(boolean isError) {
        List<ExcelColumnAttr> models = new ArrayList<>();
        //异常原因
        if (isError) {
            ExcelColumnAttr attr = ExcelColumnAttr.builder().key("errorsInfo").name("异常原因").build();
            models.add(attr);
        }
        List<String> requireFields = Arrays.asList("enCode");
        for (String key : keyMap.keySet()) {
            ExcelColumnAttr attr = ExcelColumnAttr.builder().key(key).name(keyMap.get(key)).build();
            if (requireFields.contains(key)) {
                attr.setRequire(true);
                attr.setFontColor(IndexedColors.RED.getIndex());
            }
            models.add(attr);
        }
        return models;
    }

    /**
     * 获取默认值
     */
    public List<Map<String, Object>> getDefaultList() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();

        list.add(map);
        return list;
    }
}
